﻿#include "financekeeptableview.h"

FinanceKeepTableView::FinanceKeepTableView(QWidget *parent) : MyTableView(parent)
{
    setSortingEnabled(true);
    model = new FinanceKeepStandardItemModel();

    setModel(model);

    setEditTriggers(QAbstractItemView::NoEditTriggers);
    setSelectionBehavior(QAbstractItemView::SelectRows);

    connect(&financeService, &FinanceService::getFinanceItemsSuccess,
            [=](QList<FinanceItem*> financeItems)
    {
        this->cacheFinanceItems = financeItems;
        model->reset();
        model->insertFinanceItem(financeItems, "", "");
    });
}

void FinanceKeepTableView::getFinanceItems(){
    financeService.getFinanceItems(this);
}

FinanceItem* FinanceKeepTableView::currentFinanceItem(){
    int index = currentIndex().row();

    return model->getFinanceItem(index);
}

void FinanceKeepTableView::queryFinanceItem(QString primaryDirectory, QString secondaryDirectory){
    model->reset();
    model->insertFinanceItem(cacheFinanceItems, primaryDirectory, secondaryDirectory);
}
